﻿using Pb;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Runtime.InteropServices;
using UnityEngine.SceneManagement;

public class HallModel : Game
{
    public GameObject Root;
    EginUser user = EginUser.Instance;
    EginPDK pdk = EginPDK.Instance;
    EginMahjong mahjong = EginMahjong.Instance;
    EginDN dn = EginDN.Instance;
    EginDDZ ddz = EginDDZ.Instance;
    EginXTJ xtj = EginXTJ.Instance;

    public GameObject ModifyAvatarBtn;
    public GameObject GoldPlusBtn;
    public GameObject RoomCardPlusBtn;

    public GameObject E_MailBtn;
    public GameObject RuleBtn;
    public GameObject ShareBtn;
    public GameObject SetBtn;
    public GameObject RankListBtn;
    public GameObject SignInBtn;
    public GameObject BankBtn;
    public GameObject ShopBtn;
    public GameObject GamePDKBtn1;
    public GameObject GameFishingBtn;
    public GameObject GameMahjongBtn1;
    public GameObject GameDDZBtn1;
    public GameObject GameDNBtn1;
    public GameObject GameXTJBtn1;
    public GameObject BattleBtn;
    public GameObject JoinRoomBtn1;

    public GameObject GamePDKBtn2;
    public GameObject GameMahjongBtn2;
    public GameObject GameDDZBtn2;
    public GameObject GameDNBtn2;
    public GameObject GameXTJBtn2;
    public GameObject JoinRoomBtn2;
    public GameObject ReturnBtn;

    public GameObject Right1;
    public GameObject Right2;
    public GameObject UpLeft;
    public GameObject Left;

    public UISprite Icon;
    public UITexture Avatar;
    public UILabel nickname;
    public UILabel UID;
    public UILabel coinCount;
    public UILabel roomCardCount;

    public GameObject Clue;
    //跑得快大厅
    public GameObject PDKHall;
    //捕鱼大厅
    public GameObject FishingHall;
    //麻将大厅
    public GameObject MahjongHall;
    //斗地主大厅
    public GameObject DDZHall;
    //斗牛大厅
    public GameObject DNHall;
    //天九大厅
    public GameObject XTJHall;
    public GameObject ReturnBtn2;

    //public int BankHaveCoin;        //银行里已存的钱数
    public int isHaveCoin = 0;  //已取出的钱数
    //银行
    private GameObject bankPanel;
    private BankModel bankModel;

    private AsyncOperation async;
    //保存的微信头像
    //public UITexture wxSaveAvatar;
    //public string qqKeFu;
    //public string weiXinKeFu;
    public string downloadUrl;
    SoundModel soundModel;

    public GameObject ClubBtn;

    //俱乐部
    public int _clubid = 0;
    public int _clubNum = 0;
    private static HallModel instance;

    public static HallModel Instance
    {
        get
        {
            return instance;
        }
    }
    private void Awake()
    {
        instance = this;
        if (EginUser.Instance.avatarId != null && EginUser.Instance.avatarId <= 16)
        {
            Icon.spriteName = EginUser.Instance.avatarId.ToString();
        }

        UIEventListener.Get(GameFishingBtn).onClick = ButtonClick;
        UIEventListener.Get(BattleBtn).onClick = ButtonClick;

        UIEventListener.Get(ModifyAvatarBtn).onClick = ButtonClick;
        UIEventListener.Get(GoldPlusBtn).onClick = ButtonClick;
        UIEventListener.Get(RoomCardPlusBtn).onClick = ButtonClick;
        UIEventListener.Get(E_MailBtn).onClick = ButtonClick;
        UIEventListener.Get(RuleBtn).onClick = ButtonClick;
        UIEventListener.Get(ShareBtn).onClick = ButtonClick;
        UIEventListener.Get(SetBtn).onClick = ButtonClick;

        UIEventListener.Get(RankListBtn).onClick = ButtonClick;
        UIEventListener.Get(SignInBtn).onClick = ButtonClick;
        UIEventListener.Get(BankBtn).onClick = ButtonClick;
        UIEventListener.Get(ShopBtn).onClick = ButtonClick;

        UIEventListener.Get(GamePDKBtn1).onClick = ButtonClick;
        UIEventListener.Get(GameMahjongBtn1).onClick = ButtonClick;
        UIEventListener.Get(GameDDZBtn1).onClick = ButtonClick;
        UIEventListener.Get(GameDNBtn1).onClick = ButtonClick;
        UIEventListener.Get(GameXTJBtn1).onClick = ButtonClick;
        UIEventListener.Get(JoinRoomBtn1).onClick = ButtonClick;

        UIEventListener.Get(GamePDKBtn2).onClick = ButtonClick;
        UIEventListener.Get(GameMahjongBtn2).onClick = ButtonClick;
        UIEventListener.Get(GameDDZBtn2).onClick = ButtonClick;
        UIEventListener.Get(GameDNBtn2).onClick = ButtonClick;
        UIEventListener.Get(GameXTJBtn2).onClick = ButtonClick;
        UIEventListener.Get(JoinRoomBtn2).onClick = ButtonClick;
        UIEventListener.Get(ReturnBtn).onClick = ButtonClick;
        UIEventListener.Get(ReturnBtn2).onClick = ButtonClick;


        soundModel = GameObject.Find("SoundManger").GetComponent<SoundModel>();
        soundModel.SwitchBgMusic(0);

        UIEventListener.Get(ClubBtn).onClick = ButtonClick;

    }
    private void Start()
    {
        base.StartGameSocket();
        SocketManager.Instance.socketListener = this;
        nickname.text = user.nickname;
        Debug.Log(user.nickname);

        UID.text = "ID：" + user.Uid;
        string str = user.ReturnMoney(int.Parse(user.coinCount));
        coinCount.text = str;
        roomCardCount.text = user.roomCardCount.ToString();
        //加载公告
        if (EginUser.Instance.haveNotice)
        {
            GameObject Notice = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load("Notice")));
            //Notice.transform.localPosition = new Vector3(-133, 33, 0);
        }

        //如果是微信登陆 加载微信头像
        if (user.loginControl == 1)
        {

            WXAvatarManager._instance.GetWxAvatar(int.Parse(user.Uid), Avatar, user.userUrl);
            Avatar.gameObject.SetActive(true);
            Debug.Log("显示微信头像");
        }

        CommonInfoRequest ci = new CommonInfoRequest { };
        SocketManager socketManager = SocketManager.Instance;
        socketManager.SendProtobuf1(ci, MsgId.CommonInfoRequest);

        club_chird_room.SetActive(false);

        NnRoomListRequest req = new NnRoomListRequest();
        req.GroundType = NN_GROUND_TYPE.Club;
        page = 1;
        req.Page = page;
        SocketManager sm = SocketManager.Instance;
        sm.SendProtobuf1(req, MsgId.NnRoomListRequest);

    }
    void ButtonClick(GameObject button)
    {
        if (button.name == "Gold")//加载充值金币预制体
        {
            GameObject AddMoney = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.AddMoney)));
            Add_MoneyModel addMoneyModel = AddMoney.GetComponent<Add_MoneyModel>();
            addMoneyModel.PayForGold.SetActive(false);
            addMoneyModel.PayForRoomCard.SetActive(false);
            addMoneyModel.TransferAccount.SetActive(false);
            addMoneyModel.GoldBtnBg.SetActive(false);
            addMoneyModel.RoomCardBtnBg.SetActive(false);
            addMoneyModel.TransfBtnBg.SetActive(false);
        }
        else if (button.name == "RoomCard")//加载购买房卡预制体
        {
            GameObject AddMoney = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.AddMoney)));
            Add_MoneyModel addMoneyModel = AddMoney.GetComponent<Add_MoneyModel>();
            addMoneyModel.PayForGold.SetActive(false);
            addMoneyModel.PayForRoomCard.SetActive(true);
            addMoneyModel.TransferAccount.SetActive(false);
            addMoneyModel.GoldBtnBg.SetActive(false);
            addMoneyModel.RoomCardBtnBg.SetActive(true);
            addMoneyModel.TransfBtnBg.SetActive(false);
        }
        else if (button.name == "MailBtn")//加载邮件预制体
        {
            AuthMessageRequest am = new AuthMessageRequest { PageIndex = 1 };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(am, MsgId.AuthMessageRequest);
            //GameObject E_Mail = NGUITools.AddChild(GameObject.Find("UI Root"),(GameObject)Resources.Load(HallPrafabPath.E_Mail));

        }
        else if (button.name == "RuleBtn")//加载规则预制体
        {
            //规则
            GameObject RuleBtn = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.Rule)));
        }
        else if (button.name == "ShareBtn")
        {
            //分享
            GameObject Share = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.Share));
        }
        else if (button.name == "SetBtn")//加载设置预制体
        {
            //设置
            GameObject SetBtn = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.Setting)));
        }
        // 排行榜
        else if (button.name == "RankBtn")
        {
            RecordListRequest lg = new RecordListRequest { Type = 1 };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(lg, MsgId.RecordListRequest);
            print("发送了");
        }
        else if (button.name == "SignInBtn")
        {
            //签到
            GameObject signIn = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.SignIn));
        }
        else if (button.name == "BankBtn")
        {
            //银行
            bankPanel = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.Bank));
            bankModel = bankPanel.GetComponent<BankModel>();
            bankModel.sumLabel.text = "已存入:" + user.bankCoinCount + "万金币";
        }
        //商店
        else if (button.name == "ShopBtn")
        {

            //Coin2PhoneDetailRequest cp = new Coin2PhoneDetailRequest { };
            //SocketManager socketManager = SocketManager.Instance;
            //socketManager.SendProtobuf1(cp, MsgId.Coin2PhoneDetailRequest);

            MallItemListRequest lg = new MallItemListRequest { PageIndex = 1 };
            SocketManager socketManager = SocketManager.Instance;
            socketManager.SendProtobuf1(lg, MsgId.MallItemListRequest);


        }
        else if (button.name == "MatchBtn")
        {
            //约战场
            UpLeft.transform.localPosition = new Vector3(70, 0, 0);
            ReturnBtn.SetActive(true);
            Right1.SetActive(false);
            Right2.SetActive(true);
        }
        else if (button.name == "JoinRoomBtn")
        {
            //加入房间
            GameObject RankList = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(PublicPrefabPath.JoinRoomPanel));
        }
        else if (button.name == "IconBtn")//加载头像
        {
            if (user.loginControl == 0)
            {
                GameObject Icon = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.HeadPortrait)));
            }
        }
        else if (button.name == "ReturnBtn")
        {
            //返回大厅
            UpLeft.transform.localPosition = new Vector3(0, 0, 0);
            ReturnBtn.SetActive(false);
            Right1.SetActive(true);
            Right2.SetActive(false);
        }
        else if (button.name == "ReturnBtn2")
        {
            Right1.SetActive(true);
            //Left.SetActive(true);
            ReturnBtn2.SetActive(false);
            if (Clue.activeSelf == false)
            {
                Clue.SetActive(true);
            }
            if (PDKHall.activeSelf == true)
            {
                PDKHall.SetActive(false);
            }
            else if (FishingHall.activeSelf == true)
            {
                FishingHall.SetActive(false);
            }
            else if (MahjongHall.activeSelf == true)
            {
                MahjongHall.SetActive(false);
            }
            else if (DDZHall.activeSelf == true)
            {
                DDZHall.SetActive(false);
            }
            else if (DNHall.activeSelf == true)
            {
                DNHall.SetActive(false);
            }
            else if (XTJHall.activeSelf == true)
            {
                XTJHall.SetActive(false);
            }
        }
        else if (button.name == "clueBtn")
        {
            GetClubListReq();
        }
        else if (button.name == "clue_room")
        {
            NnEnterRoomRequest req = new NnEnterRoomRequest();
            req.RoomId = int.Parse(button.transform.Find("roomid").GetComponent<UILabel>().text);
            SocketManager sm = SocketManager.Instance;
            sm.SendProtobuf1(req, MsgId.NnEnterRoomRequest);
        }
        else if (button.name == "CreateRooms")
        {
            NnRoomListRequest req = new NnRoomListRequest();
            req.GroundType = NN_GROUND_TYPE.Club;
            page += 1;
            req.Page = page;
            SocketManager sm = SocketManager.Instance;
            sm.SendProtobuf1(req, MsgId.NnRoomListRequest);
        }
        //else if (button.name == "BullfightBtn")//跳转到GameDN界面
        //{
        //    user.ControlScene = 1;
        //    user.gameType = 2;
        //    SceneManager.LoadSceneAsync("GameDN");
        //    soundModel.SwitchBgMusic(user.gameType);
        //}

        //else if (button.name == "Mahjing-HallBtn")//加载麻将大厅
        //{
        //    user.gameType = 1;
        //    user.ControlScene = 2;
        //    SceneManager.LoadSceneAsync("GameMahjong");
        //    soundModel.SwitchBgMusic(user.gameType);
        //}




        #region 进入不同的游戏大厅 金币场
        if (button.transform.parent.name == "Right1")
        {
            if (button.name == "GamePDKBtn")//跳转到PDKHall界面
            {

                user.gameType = 4;
                user.ControlScene = 2;
                Right1.SetActive(false);
                //Left.SetActive(false);
                ReturnBtn2.SetActive(true);
                PDKHall.SetActive(true);

            }
            else if (button.name == "GameFishingBtn")//跳转到FishingHall界面
            {
                Right1.SetActive(false);
                //Left.SetActive(false);
                ReturnBtn2.SetActive(true);
                FishingHall.SetActive(true);
            }
            else if (button.name == "GameMahjongBtn")//跳转到MahjongHall界面
            {

                user.gameType = 1;
                user.ControlScene = 2;
                Right1.SetActive(false);
                //Left.SetActive(false);
                ReturnBtn2.SetActive(true);
                MahjongHall.SetActive(true);
            }
            else if (button.name == "GameDDZBtn")//跳转到DDZHall界面
            {

                user.gameType = 3;
                user.ControlScene = 2;
                Right1.SetActive(false);
                //Left.SetActive(false);
                ReturnBtn2.SetActive(true);
                DDZHall.SetActive(true);
            }
            else if (button.name == "GameDNBtn")//跳转到DNHall界面
            {

                user.gameType = 2;
                user.ControlScene = 2;
                Right1.SetActive(false);
                //Left.SetActive(false);
                ReturnBtn2.SetActive(true);
                DNHall.SetActive(true);
                Clue.SetActive(false);

            }
            else if (button.name == "GameXTJBtn")//跳转到XTJHall界面
            {
                user.ControlScene = 2;
                Right1.SetActive(false);
                //Left.SetActive(false);
                ReturnBtn2.SetActive(true);
                XTJHall.SetActive(true);
                Clue.SetActive(false);
            }
        }
        #endregion 随机进入房间 金币场

        #region 创建并进入房间 好友场
        else if (button.transform.parent.name == "Right2")
        {
            if (button.name == "GamePDKBtn")//加载创建GamePDK房间界面
            {
                user.gameType = 4;
                user.ControlScene = 1;
                GameObject PDKCreate = NGUITools.AddChild(Root, (GameObject)Resources.Load(PublicPrefabPath.CreateRoom));

            }
            else if (button.name == "GameMahjongBtn")//加载创建GameMahjong房间界面
            {
                user.gameType = 1;
                user.ControlScene = 1;
                GameObject MahjongCreate = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameMahjongPrafabPath.CreateRoom));
            }
            else if (button.name == "GameDDZBtn")//加载创建GameDDZ房间界面
            {
                user.gameType = 3;
                user.ControlScene = 1;
                GameObject DDZCreate = NGUITools.AddChild(Root, (GameObject)Resources.Load(PublicPrefabPath.CreateRoom));
            }
            else if (button.name == "GameDNBtn")//加载创建GameDN房间界面
            {
                user.gameType = 2;
                user.ControlScene = 1;
                GameObject DNCreate = NGUITools.AddChild(Root, (GameObject)Resources.Load(PublicPrefabPath.CreateRoom));
            }
            else if (button.name == "GameXTJBtn")//加载创建GameXTJ房间界面
            {
                user.gameType = 101;
                user.ControlScene = 1;
                GameObject XTJCreate = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJPrafabPath.XTJCreatePanel));
            }
        }
        #endregion 创建并进入房间 好友场

    }
    private int page = 1;
    /// <summary>
    /// 监听服务器消息
    /// </summary>
    /// <param name="data"></param>
    public override void SocketReceiveMessage(byte[] data)
    {
        base.SocketReceiveMessage(data);
        byte[] dataLength = data.Skip(0).Take(2).ToArray();
        byte[] dataId = data.Skip(2).Take(4).ToArray();
        byte[] dataConcent = data.Skip(data.Length - (data.Length - 4)).ToArray();
        int TempMsgID = ProtoDataToMsg.Byte2ushort(dataId);

        #region 大厅UI
        if (TempMsgID == MsgId.CheckinResponse)//例子
        {
            Pb.CheckinResponse newpb = Pb.CheckinResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

        }
        //更改头像
        else if (TempMsgID == MsgId.ModifyAvatarResponse)
        {
            Pb.ModifyAvatarResponse newpb = Pb.ModifyAvatarResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                Destroy(GameObject.Find("HeadPortraitPanel").gameObject);
                user.logMsg = "修改成功！";
                EginUser.Instance.avatarId = newpb.AvatarId;
                Avatar.gameObject.SetActive(false);
                Icon.GetComponent<UISprite>().spriteName = newpb.AvatarId.ToString();
                user.isModifyAvatar = true;
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }

        }
        //兑换列表
        else if (TempMsgID == MsgId.Coin2PhoneDetailResponse)
        {
            Pb.Coin2PhoneDetailResponse newpb = Pb.Coin2PhoneDetailResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            GameObject ShopBtn = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.Shop)));
            ShopModel shopModel = GameObject.Find("UI Root/ShopPanel").GetComponent<ShopModel>();
            //shopModel.items = newpb.ItemList.ToList();            
        }
        //金币兑换话费
        else if (TempMsgID == MsgId.Coin2PhoneFeeResponse)
        {
            Pb.Coin2PhoneFeeResponse newpb = Pb.Coin2PhoneFeeResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //GameObject success = NGUITools.AddChild(GameObject.Find("UI Root/AccontPanel"), (GameObject)Resources.Load(HallPrafabPath.Success));
                //设置玩家的金币数量
                transform.Find("Up/Money/MoneyLabel").GetComponent<UILabel>().text = user.ReturnRelCoin(newpb.CoinCount);
                Debug.Log("兑换话费之后的金币数 = " + newpb.CoinCount);
                user.coinCount = newpb.CoinCount.ToString();
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //邮件响应
        else if (TempMsgID == MsgId.AuthMessageResponse)
        {
            Pb.AuthMessageResponse newpb = Pb.AuthMessageResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                Debug.Log("邮件数量：" + newpb.MsgList.Count);

                GameObject maik_icon = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.E_Mail)));
                GameObject.Find("E_MailPanel").GetComponent<E_MailModel>().msg_list = newpb.MsgList.ToList();

            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //某个邮件阅读响应
        else if (TempMsgID == MsgId.AuthMessageReadResponse)
        {
            Pb.AuthMessageReadResponse newpb = Pb.AuthMessageReadResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                Debug.Log("邮件已读");
            }
            else
            {
                user.logMsg = newpb.Msg;
                if (!newpb.Msg.Equals("消息已读"))
                {
                    GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
                }

            }

        }
        //新邮件通知
        else if (TempMsgID == MsgId.AuthMessageNotification)
        {
            Pb.AuthMessageNotification newpb = Pb.AuthMessageNotification.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            GameObject mailItem = NGUITools.AddChild(GameObject.Find("UI Root/E_MailPanel/UIScrollView/UIGrid"), (GameObject)Resources.Load(HallPrafabPath.E_MailItem));
        }
        //设置代理
        else if (TempMsgID == MsgId.SetAgentUidResponse)
        {
            Pb.SetAgentUidResponse newpb = Pb.SetAgentUidResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //GameObject bindMsgPanel = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.BindMsgPanel));
                user.agentUid = int.Parse(GameObject.Find("UI Root/GeneralizePanel/Input").GetComponent<UIInput>().value);
                Destroy(GameObject.Find("UI Root/GeneralizePanel"));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //红包列表
        else if (TempMsgID == MsgId.LuckyMoneyDetailResponse)
        {
            Pb.LuckyMoneyDetailResponse newpb = Pb.LuckyMoneyDetailResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            GameObject SignIn = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load(HallPrafabPath.SignIn)));
            //RedPacketModel redPacket = GameObject.Find("UI Root/RedPacketPanel").GetComponent<RedPacketModel>();
            //redPacket.LuckyMoneyItems = newpb.ItemList.ToList();
            //redPacket.haveMoneyLabel.text = user.ReturnRelCoin(newpb.TotalLuckyMoney);
            Debug.Log("领取的红包数 = " + newpb.TotalLuckyMoney);

        }
        //领取红包
        else if (TempMsgID == MsgId.LuckyMoneyReceiveResponse)
        {
            Pb.LuckyMoneyReceiveResponse newpb = Pb.LuckyMoneyReceiveResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //RedPacketModel redPacket = GameObject.Find("UI Root/RedPacketPanel").GetComponent<RedPacketModel>();                
                //int totalReceiveMoney = (int)(float.Parse(redPacket.haveMoneyLabel.text) * 100) + newpb.LuckyMoneyCount;
                //redPacket.haveMoneyLabel.text = user.ReturnRelCoin(newpb.LuckyMoneyCount);
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //红包兑换金币
        else if (TempMsgID == MsgId.LuckyMoney2CoinResponse)
        {
            Pb.LuckyMoney2CoinResponse newpb = Pb.LuckyMoney2CoinResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //设置玩家的金币数量
                user.coinCount = newpb.CoinCount.ToString();
                transform.Find("Up/Money/MoneyLabel").GetComponent<UILabel>().text = user.ReturnRelCoin(newpb.CoinCount);
                //RedPacketModel redPacket = GameObject.Find("UI Root/RedPacketPanel").GetComponent<RedPacketModel>();
                //redPacket.haveMoneyLabel.text = "0";
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        #region 银行
        // 存钱（服务器返回）
        else if (TempMsgID == MsgId.Bag2BankResponse)
        {
            Bag2BankResponse newpb = Bag2BankResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //if (BankPanel && bankModel)
                {
                    print("进入了" + newpb.BankCointCount);
                    user.bankCoinCount += bankModel.StrToInt(bankModel.getInLabel.text);
                    bankModel.sumLabel.text = "已存入：" + user.bankCoinCount + "万金币";
                    bankModel.getInLabel.text = "0万";
                }
                //设置背包里的钱数
                coinCount.text = user.ReturnMoney(newpb.BagCointCount);
                user.logMsg = "存入成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        // 取钱（服务器返回）
        else if (TempMsgID == MsgId.Bank2BagResponse)
        {
            Bank2BagResponse newpb = Bank2BagResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                //if (bankPanel && bankModel)
                {
                    user.bankCoinCount -= bankModel.StrToInt(bankModel.getOutLabel.text);
                    isHaveCoin = bankModel.StrToInt(bankModel.getOutLabel.text);
                    bankModel.sumLabel.text = "已取出：" + isHaveCoin + "万金币";
                    bankModel.getOutLabel.text = "0万";
                }
                //设置背包里的钱数
                coinCount.text = user.ReturnMoney(newpb.BagCointCount);
                user.logMsg = "取出成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        #endregion

        //微信 qq  下载链接
        else if (TempMsgID == MsgId.CommonInfoResponse)
        {
            Pb.CommonInfoResponse newpb = Pb.CommonInfoResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            downloadUrl = newpb.DownloadUrl;
            Debug.Log("downloadUrl = " + downloadUrl);
            //qqKeFu = newpb.QqKefu;
            //weiXinKeFu = newpb.WeixinKefu;
        }

        // 点击商城的响应
        else if (TempMsgID == MsgId.MallItemListResponse)
        {
            MallItemListResponse newpb = MallItemListResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            if (newpb.Status == STATUS.Success)
            {
                // 加载商城
                GameObject RankList = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.Shop));
                ShopModel shopModel = RankList.GetComponent<ShopModel>();

                if (shopModel)
                {
                    shopModel.listGood = newpb.ItemList.ToList();
                    shopModel.LogMsg();
                }
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        // 买完东西
        else if (TempMsgID == MsgId.MallOrderResponse)
        {
            MallOrderResponse newpb = MallOrderResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            if (newpb.Status == STATUS.Success)
            {

                coinCount.text = user.ReturnMoney(newpb.BagCoinCount);
                user.logMsg = "兑换成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        // 签到
        else if (TempMsgID == MsgId.SignRewardResponse)
        {
            SignRewardResponse newpb = SignRewardResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            if (newpb.Status == STATUS.Success)
            {
                user.SignTimes += 1;
                GameObject SiginReceivePanel = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load(HallPrafabPath.SiginReceivePanel)));
                ReceiveModel receiveModel = SiginReceivePanel.GetComponent<ReceiveModel>();
                if (receiveModel)
                {
                    receiveModel.SetiLabel(user.ReturnMoney(newpb.RewardCount));
                }

                coinCount.text = user.ReturnMoney(newpb.BagCointCount);

                GameObject SignInPanel = GameObject.Find("SignInPanel");
                SignInModel signInModel = SignInPanel.GetComponent<SignInModel>();
                if (signInModel)
                {
                    signInModel.GetTheSuccess();
                }
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }

        }
        // 领取救济金
        else if (TempMsgID == MsgId.GetReliefMoneyResponse)
        {
            GetReliefMoneyResponse newpb = GetReliefMoneyResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            if (newpb.Status == STATUS.Success)
            {
                user.logMsg = "领取成功";
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
                // 给金币赋值
                coinCount.text = user.ReturnMoney(newpb.BagCointCount);

                GameObject ReliefPanel = GameObject.Find("ReliefPanel");
                if (ReliefPanel)
                {
                    ReliefModel reliefModel = ReliefPanel.AddComponent<ReliefModel>();
                    UISpriteAnimation an = reliefModel.button.AddComponent<UISpriteAnimation>();
                    an.framesPerSecond = 18;
                    an.namePrefix = "gold";
                    an.loop = false;
                }
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }


        }
        // 排行榜
        else if (TempMsgID == MsgId.RecordListResponse)
        {
            RecordListResponse newpb = RecordListResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            GameObject recordPanel = GameObject.Find("RankPanel");
            if (recordPanel)
            {
                RankListModel rankListModel = recordPanel.GetComponent<RankListModel>();
                if (rankListModel)
                {
                    rankListModel.UserInfoList = newpb.UserInfoList.ToList();
                    rankListModel.ListType = newpb.Type;
                    switch (newpb.Type)
                    {
                        // 财富榜
                        case 1:
                            if (rankListModel.game1.transform.childCount > 0)
                            {
                                for (int i = 0; i < rankListModel.game1.transform.childCount; i++)
                                {
                                    Destroy(rankListModel.game1.transform.GetChild(i).gameObject);
                                }
                            }
                            break;
                        // 赚金榜
                        case 2:
                            if (rankListModel.game2.transform.childCount > 0)
                            {
                                for (int i = 0; i < rankListModel.game2.transform.childCount; i++)
                                {
                                    Destroy(rankListModel.game2.transform.GetChild(i).gameObject);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    rankListModel.LogMsg(newpb.Type);
                }
            }
            else
            {
                print("进入了");
                recordPanel = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)Resources.Load(HallPrafabPath.RankList));
                RankListBtn.SetActive(false);
                RankListModel rankListModel = recordPanel.GetComponent<RankListModel>();
                if (rankListModel)
                {
                    rankListModel.UserInfoList = newpb.UserInfoList.ToList();
                    rankListModel.ListType = newpb.Type;
                    switch (newpb.Type)
                    {
                        // 财富榜
                        case 1:
                            if (rankListModel.game1.transform.childCount > 0)
                            {
                                for (int i = 0; i < rankListModel.game1.transform.childCount; i++)
                                {
                                    Destroy(rankListModel.game1.transform.GetChild(i).gameObject);
                                }
                            }
                            break;
                        // 赚金榜
                        case 2:
                            if (rankListModel.game2.transform.childCount > 0)
                            {
                                for (int i = 0; i < rankListModel.game2.transform.childCount; i++)
                                {
                                    Destroy(rankListModel.game2.transform.GetChild(i).gameObject);
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    rankListModel.LogMsg(newpb.Type);
                }
            }
        }

        #endregion 大厅UI   

        #region 游戏开房进房处理
        //检查是哪个游戏的响应
        else if (TempMsgID == MsgId.RoomCheckResponse)
        {
            Pb.RoomCheckResponse newpb = Pb.RoomCheckResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                user.gameType = newpb.GameTypeId;
                //  user.isNN100Room = newpb.IsNn100Room;
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }

        #region 麻将

        else if (TempMsgID == MsgId.MahjongOpenRoomResponse)
        {
            Pb.MahjongOpenRoomResponse newpb = Pb.MahjongOpenRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                mahjong.CteatrUid = newpb.RoomInfo.CreaterUid;
                mahjong.roomID = newpb.RoomInfo.RoomId;
                mahjong.totalRound = newpb.RoomInfo.TotalRound;
                mahjong.seatID = newpb.SeatId;
                mahjong.roomStatus = newpb.RoomInfo.RoomStatus;
                Debug.Log(mahjong.seatID + "hall");
                //user.gameUserInfoList.Add(newpb.UserInfo);

                mahjong.FirstLoadUser = true;

                //user.CreatRoomTypeID = (int)newpb.RoomInfo.RoomTypeId;

                mahjong.baseScore = (int)newpb.RoomInfo.BaseScore;


                //存储房主到other信息里面去
                int tempSeatID;
                tempSeatID = newpb.SeatId;
                mahjong.Otheruid.Add(tempSeatID, newpb.RoomInfo.CreaterUid);
                mahjong.OtherSeatId.Add(tempSeatID, newpb.SeatId);
                mahjong.OtherSeatStatus.Add(tempSeatID, SEAT_STATUS.Sit);
                mahjong.OtherSex.Add(tempSeatID, mahjong.sex);
                mahjong.OtherIP.Add(tempSeatID, mahjong.IP);
                mahjong.OtherCoinCount.Add(tempSeatID, mahjong.coinCount);
                mahjong.OtherNickName.Add(tempSeatID, mahjong.nickname);
                mahjong.OtherAvatarid.Add(tempSeatID, mahjong.Avatar_id);
                mahjong.OtherScore.Add(tempSeatID, mahjong.Score);
                GameUserInfo userInfo = new Pb.GameUserInfo();
                userInfo.Uid = newpb.RoomInfo.CreaterUid;
                userInfo.SeatId = newpb.SeatId;
                userInfo.SeatStatus = SEAT_STATUS.Sit;
                userInfo.Sex = mahjong.sex;
                userInfo.Ip = mahjong.IP;
                userInfo.BagCoinCount = mahjong.coinCount;
                userInfo.Score = mahjong.Score;
                userInfo.AvatarId = mahjong.Avatar_id;
                userInfo.Nickname = mahjong.nickname;

                user.gameUserInfoList.Add(userInfo);
                soundModel.SwitchBgMusic(user.gameType);
                //user.gameUserInfoList.Add(newpb.UserInfo);

                if (newpb.RoomInfo.IsCardRoom == false)
                {
                    Application.LoadLevelAsync(ScenePath.GameMahjongPlay);
                }
                else
                {
                    Destroy(GameObject.Find("UI Root/CreateRoomPanel"));
                    GameObject replacePanel = NGUITools.AddChild(Root, (GameObject)Resources.Load(PublicPrefabPath.Replace));
                }
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //mj根据ID加入房间返回
        else if (TempMsgID == MsgId.MahjongEnterRoomResponse)
        {
            Pb.MahjongEnterRoomResponse newpb = Pb.MahjongEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                mahjong.CteatrUid = newpb.RoomInfo.CreaterUid;
                mahjong.roomID = newpb.RoomInfo.RoomId;
                mahjong.totalRound = newpb.RoomInfo.TotalRound;
                mahjong.seatID = newpb.SeatId;
                mahjong.roomStatus = newpb.RoomInfo.RoomStatus;
                //user.gameUserInfoList = newpb.UserInfoList.ToList();

                mahjong.baseScore = (int)newpb.RoomInfo.BaseScore;


                //存储其他玩家信息
                mahjong.Otheruid = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Uid);
                mahjong.OtherSeatId = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.SeatId);
                mahjong.OtherSeatStatus = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.SeatStatus);
                mahjong.OtherSex = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Sex);
                mahjong.OtherIP = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Ip);
                mahjong.OtherCoinCount = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.BagCoinCount);
                mahjong.OtherScore = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Score);
                mahjong.OtherNickName = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Nickname);
                mahjong.OtherAvatarid = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.AvatarId);
                Debug.Log("存储其他玩家信息");

                user.gameUserInfoList = newpb.UserInfoList.ToList();
                soundModel.SwitchBgMusic(user.gameType);
                Application.LoadLevelAsync(ScenePath.GameMahjongPlay);
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //mj随机进入房间返回
        else if (TempMsgID == MsgId.MahjongRandomEnterRoomResponse)
        {
            Pb.MahjongRandomEnterRoomResponse newpb = Pb.MahjongRandomEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                mahjong.CteatrUid = newpb.RoomInfo.CreaterUid;
                mahjong.roomID = newpb.RoomInfo.RoomId;
                mahjong.totalRound = newpb.RoomInfo.TotalRound;
                mahjong.seatID = newpb.SeatId;
                mahjong.roomStatus = newpb.RoomInfo.RoomStatus;
                //user.gameUserInfoList = newpb.UserInfoList.ToList();
                mahjong.baseScore = (int)newpb.RoomInfo.BaseScore;

                if (newpb.SeatId == 1)
                {
                    Debug.Log("存储房主到other信息里面去");
                    mahjong.FirstLoadUser = true;
                    //存储房主到other信息里面去
                    int tempSeatID;
                    tempSeatID = newpb.SeatId;
                    mahjong.Otheruid.Add(tempSeatID, newpb.RoomInfo.CreaterUid);
                    mahjong.OtherSeatId.Add(tempSeatID, newpb.SeatId);
                    mahjong.OtherSeatStatus.Add(tempSeatID, SEAT_STATUS.Sit);
                    mahjong.OtherSex.Add(tempSeatID, user.sex);
                    mahjong.OtherIP.Add(tempSeatID, user.IP);
                    mahjong.OtherCoinCount.Add(tempSeatID, mahjong.coinCount);
                    mahjong.OtherNickName.Add(tempSeatID, mahjong.nickname);
                    mahjong.OtherAvatarid.Add(tempSeatID, mahjong.Avatar_id);
                    mahjong.OtherScore.Add(tempSeatID, mahjong.Score);
                }
                //存储其他玩家信息
                mahjong.Otheruid = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Uid);
                mahjong.OtherSeatId = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.SeatId);
                mahjong.OtherSeatStatus = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.SeatStatus);
                mahjong.OtherSex = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Sex);
                mahjong.OtherIP = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Ip);
                mahjong.OtherCoinCount = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.BagCoinCount);
                mahjong.OtherScore = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Score);
                mahjong.OtherNickName = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.Nickname);
                mahjong.OtherAvatarid = newpb.UserInfoList.ToDictionary(t => t.SeatId, t => t.AvatarId);
                mahjong.seatStatus = mahjong.OtherSeatStatus[newpb.SeatId]; //存储玩家的seatstatus
                Debug.Log("存储其他玩家信息");

                user.gameUserInfoList = newpb.UserInfoList.ToList();
                soundModel.SwitchBgMusic(user.gameType);
                Application.LoadLevelAsync(ScenePath.GameMahjongPlay);
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }

        }
        #endregion 

        //斗地主
        #region 斗地主
        else if (TempMsgID == MsgId.DdzOpenRoomResponse)
        {
            Pb.DdzOpenRoomResponse newpb = Pb.DdzOpenRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                ddz.createrUid = newpb.RoomInfo.CreaterUid;
                ddz.roomId = newpb.RoomInfo.RoomId;
                ddz.totalRound = newpb.RoomInfo.TotalRound;
                ddz.seatId = newpb.SeatId;
                ddz.roomStatus = newpb.RoomInfo.RoomStatus;
                Debug.Log(ddz.seatId + "hall");
                user.gameUserInfoList.Add(newpb.UserInfo);

                StartCoroutine(StartGameDDZ());


            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        else if (TempMsgID == MsgId.DdzEnterRoomResponse)
        {
            Pb.DdzEnterRoomResponse newpb = Pb.DdzEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                ddz.createrUid = newpb.RoomInfo.CreaterUid;
                ddz.roomId = newpb.RoomInfo.RoomId;
                ddz.totalRound = newpb.RoomInfo.TotalRound;
                ddz.seatId = newpb.SeatId;
                ddz.roomStatus = newpb.RoomInfo.RoomStatus;
                user.gameUserInfoList = newpb.UserInfoList.ToList();
                StartCoroutine(StartGameDDZ());
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }

        }
        //斗地主随机进入房间消息响应
        else if (TempMsgID == MsgId.DdzRandomEnterRoomResponse)
        {
            Pb.DdzRandomEnterRoomResponse newpb = Pb.DdzRandomEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                ddz.createrUid = newpb.RoomInfo.CreaterUid;
                ddz.roomId = newpb.RoomInfo.RoomId;
                ddz.totalRound = newpb.RoomInfo.TotalRound;
                ddz.seatId = newpb.SeatId;
                ddz.roomStatus = newpb.RoomInfo.RoomStatus;
                user.gameUserInfoList = newpb.UserInfoList.ToList();
                StartCoroutine(StartGameDDZ());
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        #endregion 斗地主
        //跑的快
        #region 跑的快
        else if (TempMsgID == MsgId.RunOpenRoomResponse)
        {
            Pb.RunOpenRoomResponse newpb = Pb.RunOpenRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                pdk.createrUid = newpb.RoomInfo.CreaterUid;
                pdk.roomId = newpb.RoomInfo.RoomId;
                pdk.totalRound = newpb.RoomInfo.TotalRound;
                pdk.seatId = newpb.UserInfo.SeatId;
                pdk.roomStatus = newpb.RoomInfo.RoomStatus;
                pdk.baseScore = newpb.RoomInfo.BaseScore;
                pdk.isCardRoom = newpb.RoomInfo.IsCardRoom;
                Debug.Log("开房时的模式 = " + newpb.RoomInfo.IsCardRoom);
                pdk.isAgentRoom = newpb.RoomInfo.IsAgentRoom;
                user.gameUserInfoList.Add(newpb.UserInfo);
                Debug.Log("跑的快游戏开房底分" + newpb.RoomInfo.BaseScore);
                if (newpb.RoomInfo.IsAgentRoom == false)
                {
                    StartCoroutine(StartGamePDK());
                }
                else
                {
                    Destroy(GameObject.Find("UI Root/CreateRoomPanel"));
                    GameObject replacePanel = NGUITools.AddChild(Root, (GameObject)Resources.Load(GamePDKPrefabPath.PDKReplaceCreate));
                    PDKReplace replace = replacePanel.GetComponent<PDKReplace>();
                    if (newpb.RoomInfo.IsCardRoom == false)
                    {
                        replace.topLabel.text = "跑得快房间（金币模式）创建成功";
                        replace.goldContent1.text = user.ReturnRelCoinForBrief(newpb.RoomInfo.BaseScore);
                        replace.goldContent2.text = newpb.RoomInfo.TotalRound + "局";
                        replace.goldPattern.SetActive(true);
                        replace.cardPattern.SetActive(false);
                    }
                    else
                    {
                        replace.topLabel.text = "跑得快房间（房卡模式）创建成功";
                        replace.cardContent.text = newpb.RoomInfo.TotalRound + "局";
                        replace.goldPattern.SetActive(false);
                        replace.cardPattern.SetActive(true);
                    }
                    replace.roomIdLabel.text = newpb.RoomInfo.RoomId.ToString();
                }
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        else if (TempMsgID == MsgId.RunEnterRoomResponse)
        {
            Pb.RunEnterRoomResponse newpb = Pb.RunEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                pdk.createrUid = newpb.RoomInfo.CreaterUid;
                pdk.roomId = newpb.RoomInfo.RoomId;
                pdk.totalRound = newpb.RoomInfo.TotalRound;
                pdk.seatId = newpb.SeatId;
                pdk.baseScore = newpb.RoomInfo.BaseScore;
                pdk.roomStatus = newpb.RoomInfo.RoomStatus;
                pdk.isCardRoom = newpb.RoomInfo.IsCardRoom;
                Debug.Log("进房时的房间模式 = " + newpb.RoomInfo.IsCardRoom);
                pdk.isAgentRoom = newpb.RoomInfo.IsAgentRoom;
                user.gameUserInfoList = newpb.UserInfoList.ToList();
                user.ControlScene = 1;
                StartCoroutine(StartGamePDK());
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }

        //跑的快随机进入房间消息响应
        else if (TempMsgID == MsgId.RunRandomEnterRoomResponse)
        {
            Pb.RunRandomEnterRoomResponse newpb = Pb.RunRandomEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                pdk.createrUid = newpb.RoomInfo.CreaterUid;
                pdk.roomId = newpb.RoomInfo.RoomId;
                pdk.totalRound = newpb.RoomInfo.TotalRound;
                pdk.seatId = newpb.SeatId;
                pdk.roomStatus = newpb.RoomInfo.RoomStatus;
                pdk.baseScore = newpb.RoomInfo.BaseScore;
                pdk.isCardRoom = newpb.RoomInfo.IsCardRoom;
                pdk.isAgentRoom = newpb.RoomInfo.IsAgentRoom;
                user.gameUserInfoList = newpb.UserInfoList.ToList();
                StartCoroutine(StartGamePDK());
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }

        #endregion 跑的快
        //斗牛
        #region 斗牛
        //else if (TempMsgID == MsgId.NnOpenRoomResponse)
        //{
        //    Pb.NnOpenRoomResponse newpb = Pb.NnOpenRoomResponse.Parser.ParseFrom(dataConcent);
        //    Debug.LogError("消息ID" + TempMsgID + "消息内容" + newpb);
        //    if (newpb.Status == STATUS.Success)
        //    {

        //        dn.createrUid = newpb.RoomInfo.CreaterUid;
        //        dn.roomId = newpb.RoomInfo.RoomId;
        //        dn.totalRound = newpb.RoomInfo.TotalRound;
        //        dn.seatId = newpb.SeatId;
        //        dn.roomStatus = newpb.RoomInfo.RoomStatus;
        //        Debug.Log(dn.seatId + "hall");
        //        user.gameUserInfoList.Add(newpb.UserInfo);

        //        soundModel.SwitchBgMusic(user.gameType);
        //        Application.LoadLevelAsync(ScenePath.GameDNPlay);
        //    }
        //    else
        //    {
        //        user.logMsg = newpb.Msg;
        //        GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
        //    }
        //}

        else if (TempMsgID == MsgId.NnEnterRoomResponse)
        {
            Pb.NnEnterRoomResponse newpb = Pb.NnEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                dn.createrUid = newpb.RoomInfo.CreaterUid;
                dn.roomId = newpb.RoomInfo.RoomId;
                dn.totalRound = newpb.RoomInfo.TotalRound;
                dn.seatId = newpb.SeatId;
                dn.roomStatus = newpb.RoomInfo.RoomStatus;
                user.gameUserInfoList = newpb.UserInfoList.ToList();
                soundModel.SwitchBgMusic(user.gameType);
                Application.LoadLevelAsync(ScenePath.GameDNPlay);
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //斗牛随机进入房间消息响应
        else if (TempMsgID == MsgId.NnRandomEnterRoomResponse)
        {
            Pb.NnRandomEnterRoomResponse newpb = Pb.NnRandomEnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                dn.createrUid = newpb.RoomInfo.CreaterUid;
                dn.roomId = newpb.RoomInfo.RoomId;
                dn.totalRound = newpb.RoomInfo.TotalRound;
                dn.seatId = newpb.SeatId;
                dn.roomStatus = newpb.RoomInfo.RoomStatus;
                user.gameUserInfoList = newpb.UserInfoList.ToList();
                soundModel.SwitchBgMusic(user.gameType);
                Application.LoadLevelAsync(ScenePath.GameDNPlay);
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        else if (TempMsgID == MsgId.Nn100EnterRoomResponse)
        {
            Pb.Nn100EnterRoomResponse newpb = Pb.Nn100EnterRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {
                dn.createrUid = newpb.RoomInfo.CreaterUid;
                dn.roomId = newpb.RoomInfo.RoomId;
                dn.totalRound = newpb.RoomInfo.TotalRound;
                dn.roomStatus = newpb.RoomInfo.RoomStatus;
                user.gameUserInfoList = newpb.UserInfoList.ToList();
                dn.chipInfo = newpb.ChipInfo;
                dn.bankerInfo = newpb.BankerUserInfo;
                dn.chairUserList = newpb.ChairUserList.ToList();
                //确定庄家
                for (int i = 0; i < newpb.UserInfoList.Count; i++)
                {
                    if (newpb.UserInfoList[i].IsBanker == true)
                    {
                        dn.bankerInfo = user.gameUserInfoList[i];
                    }
                }
                Debug.Log("自己加入房间了" + Time.time);
                Debug.Log("椅子上的玩家数量 = " + newpb.ChairUserList.Count);
                Debug.Log("房间里的玩家数量 = " + newpb.UserInfoList.Count);
                Debug.Log("庄家UId = " + newpb.BankerUserInfo.Uid);
                for (int i = 0; i < newpb.UserInfoList.Count; i++)
                {
                    Debug.Log("玩家Uid = " + user.gameUserInfoList[i].Uid);
                    if (user.gameUserInfoList[i].IsBanker == true)
                    {
                        Debug.Log("庄家Uid = " + user.gameUserInfoList[i].Uid);
                    }
                }
                for (int i = 0; i < newpb.ChairUserList.Count; i++)
                {
                    Debug.Log("椅子上的玩家Uid = " + newpb.ChairUserList[i].Uid);
                }
                soundModel.SwitchBgMusic(user.gameType);
                Application.LoadLevelAsync(ScenePath.GameDNPlay100);
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject msg = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }

        #endregion 斗牛

        #region 小天九
        else if (TempMsgID == MsgId.PaiEnterRoundResponse)
        {
            Pb.PaiEnterRoundResponse newpb = Pb.PaiEnterRoundResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            Debug.Log("进房响应");
            if (newpb.Status == (int)STATUS.Success)
            {
                xtj.newpb = newpb;
                if (newpb.RoundNumber != 0)
                {
                    GameObject create = GameObject.Find("UI Root/XTJCreatePanel");
                    if (create != null)
                    {
                        Destroy(create);
                    }
                    xtj.roomId = newpb.RoundNumber;
                    GameObject replace = NGUITools.AddChild(Root, (GameObject)Resources.Load(GameXTJPrafabPath.XTJReplacePanel));
                }
            }
            else
            {
                user.logMsg = newpb.Msg;
                GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            }
        }
        else if (TempMsgID == MsgId.PaiEnterRoundBroadcast)
        {
            Pb.PaiEnterRoundBroadcast newpb = Pb.PaiEnterRoundBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);
            //if (newpb.Status == (int)STATUS.Success)
            {
                xtj.playersList = newpb.Round.PlayerInfo.ToList();
                xtj.roomStatus = newpb.Round.Status;
                xtj.currentRound = newpb.Round.Total;
                xtj.roomId = newpb.Round.RoundNumber;
                xtj.roundId = newpb.Round.Id;
                Debug.Log("房间ID：" + newpb.Round.RoundNumber);
                xtj.level = newpb.Round.Level;
                Debug.Log("房间Level：" + newpb.Round.Level);
                xtj.roundType = newpb.Round.RoundType;
                xtj.chipList = newpb.Round.ChipLevels.ToList();
                xtj.cardHistory = newpb.Round.CardHistory.ToList();
                xtj.roundCardNum = xtj.cardHistory.Count / 8;
                xtj.roundNum = newpb.Round.Total;
                xtj.playersNum = newpb.Round.OnlineNumber;
                xtj.roundType = newpb.Round.RoundType;
                xtj.createrUid = newpb.Round.CreatorId;
                xtj.systemCoin = newpb.Round.SystemCoin;
                xtj.bankerInfo = newpb.Round.MasterInfo;
                xtj.bankerId = newpb.Round.MasterInfo.Id;
                soundModel.SwitchBgMusic(5);

                if (newpb.Round.RoundType == 1)
                {
                    SceneManager.LoadSceneAsync(ScenePath.GameXTJ);
                }
                else if (newpb.Round.RoundType == 3)
                {
                    SceneManager.LoadSceneAsync(ScenePath.GameXTJOfFriend);
                }
                else if (newpb.Round.RoundType == 4)
                {
                    SceneManager.LoadSceneAsync(ScenePath.GameXTJ100);
                }


            }
            //else
            //{
            //    user.logMsg = newpb.Msg;
            //    GameObject Set = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            //}
        }
        //接收准备通知的消息
        else if (TempMsgID == MsgId.PaiRoundReadyBroadcast)
        {
            Pb.PaiRoundReadyBroadcast newpb = Pb.PaiRoundReadyBroadcast.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + newpb);

            xtj.isReady = true;
        }

        #endregion 小天九
        //....
        #endregion 游戏开房进房处理
        #region 俱乐部
        if (TempMsgID == MsgId.NnJoinClubResponse)
        {
            NnJoinClubResponse resp = NnJoinClubResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + resp);
            if (resp.Status == STATUS.Success)
            {
                user.logMsg = "申请加入俱乐部成功~";
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
            else
            {
                user.logMsg = resp.Msg;
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //获取俱乐部成员
        else if (TempMsgID == MsgId.NnClubMembersResponse)
        {
            NnClubMembersResponse resp = NnClubMembersResponse.Parser.ParseFrom(dataConcent);
            Debug.Log("消息ID" + TempMsgID + "消息内容" + resp);
            if (resp.Members.Count == 0)
            {

                user.logMsg = "没有更多~";
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));

                if (ClubhuizhangModel.Instance != null)
                {

                    ClubhuizhangModel.Instance.ShowNowState();
                }
            }
            else
            {
                if (resp.Members[0].Id == int.Parse(user.Uid))//会长
                {
                    if (ClubhuizhangModel.Instance == null)
                    {
                        GameObject obj = GameObject.Instantiate(Resources.Load("Club/ClubhuizhangPanul") as GameObject);
                        obj.name = "ClubhuizhangPanul";
                        obj.transform.SetParent(Root.transform);
                        obj.transform.localScale = Vector3.one;
                        obj.transform.localPosition = Vector3.zero;
                        obj.transform.localRotation = Quaternion.identity;

                    }

                    ClubhuizhangModel.Instance.JibenInit(resp);
                }
                else
                {
                    if (ClubChengyuanModel.Instance == null)
                    {
                        GameObject obj = GameObject.Instantiate(Resources.Load("Club/ClubchengyuanPanul") as GameObject);
                        obj.name = "ClubchengyuanPanul";
                        obj.transform.SetParent(Root.transform);
                        obj.transform.localScale = Vector3.one;
                        obj.transform.localPosition = Vector3.zero;
                        obj.transform.localRotation = Quaternion.identity;
                    }
                    ClubChengyuanModel.Instance.Init(resp);
                }
            }
        }
        //获取自己的俱乐部名称
        else if (TempMsgID == MsgId.NnClubListResponse)
        {
            NnClubListResponse resp = NnClubListResponse.Parser.ParseFrom(dataConcent);
            if (resp.Clubs.Count == 0)
            {
                GameObject obj = GameObject.Instantiate(Resources.Load("Club/JoinClub") as GameObject);
                obj.name = "JoinClub";
                obj.transform.SetParent(Root.transform);
                obj.transform.localScale = Vector3.one;
                obj.transform.localPosition = Vector3.zero;
                obj.transform.localRotation = Quaternion.identity;
            }
            else
            {
                for (int i = 0; i < resp.Clubs.Count; i++)
                {
                    _clubid = resp.Clubs[i].Id;
                    _clubNum = resp.Clubs[i].MemberCount;
                    Debug.LogError("--------" + _clubid + "=------" + _clubNum);
                }
                //第一次打开显示第一页
                NnClubMembersRequest req = new NnClubMembersRequest();
                req.ClubId = _clubid;
                req.Page = 1;
                SocketManager sm = SocketManager.Instance;
                sm.SendProtobuf1(req, MsgId.NnClubMembersRequest);
            }

        }
        //创建俱乐部应答
        else if (TempMsgID == MsgId.NnCreateClubResponse)
        {
            NnCreateClubResponse resp = NnCreateClubResponse.Parser.ParseFrom(dataConcent);
            if (resp.Status == STATUS.Success)
            {
                user.logMsg = "恭喜创建成功~";
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));

            }
            else
            {
                user.logMsg = resp.Msg;
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
        }
        //获取牛牛房间应答
        else if (TempMsgID == MsgId.NnRoomListResponse)
        {
            NnRoomListResponse resp = NnRoomListResponse.Parser.ParseFrom(dataConcent);
            if (resp.Rooms.Count == 0 && resp.Status == STATUS.Success &&page>1)
            {
                user.logMsg = "没有更多俱乐部房间了~";
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
            if (DNHall.activeSelf == true)//斗牛大厅
            {
                InitDNRoomList(resp);
            }
            else if (XTJHall.activeSelf == true)//小天九大厅
            {

            }
            else//俱乐部房间
            {
                if (ClubhuizhangModel.Instance)//会长加载
                {
                    if (resp.Status == STATUS.Success)
                    {
                        try
                        {
                            ClubhuizhangModel.Instance.KaifangInit(resp);
                        }
                        catch (System.Exception)
                        {
                            Debug.LogError("ClubListenter----146行，异常(Instance失败)");
                        }
                        SetClubRoomList(resp);
                    }
                    else
                    {
                        user.logMsg = resp.Msg;
                        GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
                    }
                }
                else//更新主场景俱乐部房间
                {
                    Debug.LogError("---NnRoomListResponse---");

                    SetClubRoomList(resp);
                }
            }

        }
        //获取房间规则应答
        else if (TempMsgID == MsgId.NnRoomOptionsResponse)
        {
            Debug.LogError("------NnRoomOptionsResponse--------");
            NnRoomOptionsResponse resp = NnRoomOptionsResponse.Parser.ParseFrom(dataConcent);
            try
            {
                ClubhuizhangModel.Instance.KaiFangJieShaoInit(resp);
            }
            catch (System.Exception)
            {
                Debug.LogError("ClubListenter----165行，异常(Instance失败)");
            }
        }
        ////俱乐部创建房间应答(暂时没用到，俱乐部创建房间在HallModel----NNOpenRoom)
        //else if (TempMsgID == MsgId.NnCreateRoomResponse)
        //{
        //    NnCreateRoomResponse resp = NnCreateRoomResponse.Parser.ParseFrom(dataConcent);
        //    if (resp.Status == STATUS.Success)
        //    {
        //        user.logMsg = "创建房间成功~";
        //        GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
        //    }
        //    else
        //    {
        //        user.logMsg = resp.Msg;
        //        GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
        //    }
        //}
        //获取俱乐部入会申请的列表
        else if (TempMsgID == MsgId.NnReviewingMemberListResponse)
        {
            NnReviewingMemberListResponse resp = NnReviewingMemberListResponse.Parser.ParseFrom(dataConcent);
            if (ClubhuizhangModel.Instance != null)
            {
                ClubhuizhangModel.Instance.RuHuiInit(resp);
            }

        }
        //处理玩家请求
        else if (TempMsgID == MsgId.NnHandleMemberResponse)
        {
            NnHandleMemberResponse resp = NnHandleMemberResponse.Parser.ParseFrom(dataConcent);

            if (resp.Status == STATUS.Success)
            {
                //界面没有关闭
                if (ClubhuizhangModel.Instance != null)
                {
                    if (ClubhuizhangModel.Instance._currentState == ButtonState.JiBenState)
                    {
                        user.logMsg = "踢出成功";
                        GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
                    }
                    else
                    {
                        user.logMsg = "操作成功";
                        GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));

                    }

                }
            }
            else
            {
                user.logMsg = resp.Msg;
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
        }
        else if (TempMsgID == MsgId.NnHandleMemberBroadcast)
        {
            NnHandleMemberBroadcast resp = NnHandleMemberBroadcast.Parser.ParseFrom(dataConcent);
            user.logMsg = "您被移除俱乐部~";
            GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
        }
        else if (TempMsgID == MsgId.NnOpenRoomResponse)
        {
            Pb.NnOpenRoomResponse newpb = Pb.NnOpenRoomResponse.Parser.ParseFrom(dataConcent);
            Debug.LogError("消息ID" + TempMsgID + "消息内容" + newpb);
            if (newpb.Status == STATUS.Success)
            {

                if (newpb.SeatId == 0)//不在房间
                {
                    if (DNHall.activeSelf == true)//斗牛大厅
                    {
                        NnRoomListRequest reqs = new NnRoomListRequest();
                        reqs.GroundType = NN_GROUND_TYPE.Hall;
                        reqs.RoomType = NNCoinJoinRoom.Instance._current_type;
                        reqs.Page = 1;
                        SocketManager sms = SocketManager.Instance;
                        sms.SendProtobuf1(reqs, MsgId.NnRoomListRequest);
                    }
                    else
                    {
                        NnRoomListRequest req = new NnRoomListRequest();
                        req.GroundType = NN_GROUND_TYPE.Club;
                        req.Page = 1;
                        SocketManager sm = SocketManager.Instance;
                        sm.SendProtobuf1(req, MsgId.NnRoomListRequest);
                    }


                }
                else
                {
                    dn.createrUid = newpb.RoomInfo.CreaterUid;
                    dn.roomId = newpb.RoomInfo.RoomId;
                    dn.totalRound = newpb.RoomInfo.TotalRound;
                    dn.seatId = newpb.SeatId;
                    dn.roomStatus = newpb.RoomInfo.RoomStatus;
                    Debug.Log(dn.seatId + "hall");
                    user.gameUserInfoList.Add(newpb.UserInfo);

                    //soundModel.SwitchBgMusic(user.gameType);
                    Application.LoadLevelAsync(ScenePath.GameDNPlay);
                }


            }
        }
        #endregion


        //网络异常
        else if (TempMsgID == MsgId.NetWorkAbnormalMessage)
        {
            GameObject NetWorkAbnormal = NGUITools.AddChild(GameObject.Find("UI Root").gameObject, (GameObject)(Resources.Load("NetWorkAbnormal")));
        }

    }
    public Transform club_grid_room;
    public GameObject club_chird_room;

    protected IEnumerator StartGamePDK()
    {
        GameObject LoadSceneAsync = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("Public/LoadSceneAsync")));
        //异步读取场景。
        //Globe.loadName 就是A场景中需要读取的C场景名称。
        //async = Application.LoadLevelAsync(ScenePath.GameDDZPlay);
        soundModel.SwitchBgMusic(user.gameType);
        SceneManager.LoadSceneAsync(ScenePath.GamePDKPlay);
        //async.allowSceneActivation = false;
        //读取完毕后返回， 系统会自动进入C场景
        yield return async;
    }

    protected IEnumerator StartGameDDZ()
    {
        GameObject LoadSceneAsync = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("Public/LoadSceneAsync")));
        //异步读取场景。
        //Globe.loadName 就是A场景中需要读取的C场景名称。
        //async = Application.LoadLevelAsync(ScenePath.GameDDZPlay);
        soundModel.SwitchBgMusic(user.gameType);
        Application.LoadLevelAsync(ScenePath.GameDDZPlay);
        //async.allowSceneActivation = false;
        //读取完毕后返回， 系统会自动进入C场景
        yield return async;
    }
    IEnumerator GetWWWFACE(string url)
    {
        if (url != "")
        {
            WWW www = new WWW(url);


            yield return www;
            if (www.isDone)
            {
                if (www.error == null) { }
                Avatar.mainTexture = www.texture;
                Avatar.gameObject.SetActive(true);
                //wxSaveAvatar.mainTexture = www.texture;
            }
            else
            {

            }
            www.Dispose();
        }

    }
    /// <summary>
    /// 获取自己俱乐部数量列表
    /// </summary>
    private void GetClubListReq()
    {
        NnClubListRequest req = new NnClubListRequest();
        SocketManager sm = SocketManager.Instance;
        sm.SendProtobuf1(req, MsgId.NnClubListRequest);
    }
    private List<int> _club_nums = new List<int>();//Hall中俱乐部所有的房间id
    /// <summary>
    /// 刷新主界面俱乐部房间
    /// </summary>
    /// <param name="resp"></param>
    public void SetClubRoomList(NnRoomListResponse resp)
    {
        Debug.LogError("--HallModel--1791-->>>俱乐部房间数目：" + resp.Rooms.Count);
        try
        {
            Destroy(club_grid_room.Find("CreateRooms").gameObject);

            if (resp.Rooms.Count == 0 && resp.Status == STATUS.Success)
            {
                user.logMsg = "没有更多俱乐部房间~";
                GameObject Set = NGUITools.AddChild(Root, (GameObject)(Resources.Load("LogMsg")));
            }
        }
        catch (System.Exception)
        {

            Debug.LogError("---第一次打开加载俱乐部房间");
        }

        if (resp.Status == STATUS.Success)
        {
            for (int i = 0; i < resp.Rooms.Count; i++)
            {
                if (!resp.Rooms[i].IsFull && !_club_nums.Contains(resp.Rooms[i].RoomId))
                {
                    GameObject go = GameObject.Instantiate(club_chird_room);
                    go.SetActive(true);
                    go.transform.Find("Label").GetComponent<UILabel>().text = string.Format("已有：{0}人、{1}底分", resp.Rooms[i].MemberCount, resp.Rooms[i].Score);
                    go.name = "clue_room";
                    go.transform.Find("roomid").transform.GetComponent<UILabel>().text = resp.Rooms[i].RoomId.ToString();
                    go.transform.SetParent(club_grid_room);
                    go.transform.localPosition = Vector3.zero;
                    go.transform.localRotation = Quaternion.identity;
                    go.transform.localScale = Vector3.one;
                    UIEventListener.Get(go).onClick = ButtonClick;
                    _club_nums.Add(resp.Rooms[i].RoomId);
                }

            }
            GameObject gos = GameObject.Instantiate(club_chird_room);
            gos.SetActive(true);
            gos.name = "CreateRooms";
            gos.transform.Find("roomid").gameObject.SetActive(false);
            gos.transform.Find("douniu").gameObject.SetActive(false);
            gos.transform.Find("Label").GetComponent<UILabel>().text = "点击加载更多房间";
            gos.transform.Find("Background").GetComponent<UISprite>().spriteName = "none";
            gos.transform.SetParent(club_grid_room);
            gos.transform.localPosition = Vector3.zero;
            gos.transform.localRotation = Quaternion.identity;
            gos.transform.localScale = Vector3.one;
            UIEventListener.Get(gos).onClick = ButtonClick;
            club_grid_room.transform.GetComponent<UIGrid>().enabled = true;
        }
        else
        {
            //user.logMsg = resp.Msg;
            //GameObject msg = NGUITools.AddChild(GameObject.Find("UI Root"), (GameObject)(Resources.Load("LogMsg")));
            Debug.Log("------再次获取俱乐部房间列表------");
            NnRoomListRequest req = new NnRoomListRequest();

            req.GroundType = NN_GROUND_TYPE.Club;
            page = 1;
            req.Page = page;
            SocketManager sm = SocketManager.Instance;
            sm.SendProtobuf1(req, MsgId.NnRoomListRequest);
        }
    }
    /// <summary>
    /// 刷新斗牛大厅房间列表
    /// </summary>
    /// <param name="resp"></param>
    public void InitDNRoomList(NnRoomListResponse resp)
    {
        gameObject.transform.Find("GameHall/DN").GetComponent<DNGameHall>().Init(resp);
    }

    void OnDestroy()
    {
        instance = null;
    }
}